package com.heima.JD;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * 1.库存
 * 创建一个goods类
 * 创建一个ArrayList将goods存入
 * 2.秒杀
 * 设置开始以及结束时间
 *
 */
public class JDShopping {
    public static void main(String[] args) {
        ArrayList<Goods> list = new ArrayList<Goods>();
        Goods goods1 = new Goods("鸭蛋",10);
        list.add(goods1);
        list.add(new Goods("摇头风扇",2));
        list.add(new Goods("瓢虫项链",5));
        start(list);

    }

public static void start(ArrayList<Goods> list){
    String startTime = "00:00:00";
    String endTime = "00:05:00";
    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss");
    LocalTime now = LocalTime.now();
    LocalTime start = LocalTime.parse(startTime, dtf);
    LocalTime end = LocalTime.parse(endTime, dtf);
    Scanner sc = new Scanner(System.in);
        while(true){
            for (int i = 0; i < list.size(); i++) {
                System.out.println("商品序号："+(i+1)+list.get(i));
            }
            System.out.println("请选择需要秒杀的商品：");
            int num = sc.nextInt();
            if (now.isAfter(start)&&now.isBefore(end)){
                switch (num){
                    case 1:
                        if (list.get(0).getCount()==0){
                            System.out.println("没有库存");
                        }else {
                            list.get(0).count();
                        }
                        break;
                    case 2:
                        if (list.get(1).getCount()==0){
                            System.out.println("没有库存");
                        }else {
                            list.get(1).count();
                        }
                        break;
                    case 3:
                        if (list.get(2).getCount()==0){
                            System.out.println("没有库存");
                        }else {
                            list.get(2).count();
                        }
                        break;
                }
            }else {
                System.out.println("不在秒杀时间内");
            }

        }
}

}
